package com.curvebreakers.wheresmystuff.tests.model;

// Josh Williams

import java.util.Date;

import com.curvebreakers.wheresmystuff.model.Category;
import com.curvebreakers.wheresmystuff.model.Entry;
import com.curvebreakers.wheresmystuff.model.EntryType;

import junit.framework.Assert;
import android.os.Parcel;
import android.test.AndroidTestCase;

public class EntryParcelableTest extends AndroidTestCase {
	/**
	 * Tests whether the Entry correctly adds and retrieves its instance variables to and from the Parcel.
	 * 
	 * @throws Throwable
	 */
	public void testParcelable() throws Throwable {
		Entry e = new Entry.Builder()
			.zipCode("30332")
			.category(Category.HEIRLOOM)
			.entryType(EntryType.LOST)
			.date(new Date(300000))
			.description("test")
			.id(100)
			.title("test title")
			.resolved(true)
			.reward(100)
			.userId(1)
			.userEmail("test@email.com")
			.build();
		Parcel p = Parcel.obtain();
		e.writeToParcel(p, 0);
		p.setDataPosition(0);
		Entry e2 = Entry.CREATOR.createFromParcel(p);
		Assert.assertTrue(e2.getDateString().equals(e.getDateString()));
		Assert.assertTrue(e2.getDescription().equals(e.getDescription()));
		Assert.assertTrue(e2.getTitle().equals(e.getTitle()));
		Assert.assertTrue(e2.getStatusString().equals(e.getStatusString()));
		Assert.assertTrue(e2.getUserEmail().equals(e.getUserEmail()));
		Assert.assertTrue(e2.getZipCode().equals(e.getZipCode()));
		Assert.assertTrue(e2.getDate().equals(e.getDate()));
		Assert.assertTrue(e2.isResolved() == e.isResolved());
		Assert.assertTrue(e2.getEntryType() == e.getEntryType());
		Assert.assertTrue(e2.getId() == e.getId());
		Assert.assertTrue(e2.getUserId() == e.getUserId());
		Assert.assertTrue(e2.getCategory() == e.getCategory());
		p.recycle();
	}
}
